<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class RegisterController extends Controller
{
    //用户注册
    public function index()
    {
        return view('register.index');
    }

    //用户注册
    public function register()
    {
        $this->validate(request(), [
            'name'  => 'required|min:5|max:20|unique:users,name',
            'email'  => 'required|email|unique:users,email',
            'password'  =>'required|min:6|confirmed'
        ], [
            'name.unique'   => '用户名已经存在',
            'email.unique'  => '邮箱已经存在',
        ]);

        $name = request('name');
        $email = request('email');
        $password = bcrypt(request('password'));
        User::create(compact('name', 'email', 'password'));

        return redirect('/login');
    }
}
